<?php 
/*
 * RS 材料产品模板
 */
?>
<form class="form-search">
    <div class="input-append">
        <input placeholder="Item name..." name="ProductBase[p_name]" type="text" class="span2 search-query">
        <button type="submit" class="btn">Search</button>
    </div>
</form>
<?php
/**
 * 注册wowhead的toltips的JS，来对WOW产品进行鼠标提示
 */
//Yii::app()->clientScript->registerScriptFile('http://static.wowhead.com/widgets/power.js');
//Yii::app()->clientScript->registerScriptFile('http://d3db.com/static/js/external.js');
//$script_info = 'var wowhead_tooltips = { "colorlinks": false, "iconizelinks": false, "renamelinks": false }';
//Yii::app()->clientScript->registerScript('wowhead', $script_info, CClientScript::POS_HEAD);

$pModel = new ProductBase;
$pModel->p_game = $model->game_id;
$pModel->p_type = $model->product_model;
if(isset($_GET['ProductBase']['p_name'])){
    $pModel->p_name = trim($_GET['ProductBase']['p_name']);
}
$currency = $this->changeCurrency(0);
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'sys-admin-grid',
    'dataProvider' => $pModel->getProductsByType(),
    'cssFile' => '',
    'ajaxUpdate' => false,
    'htmlOptions' => array('class' => ''),
    'template' => '{summary}{items}{pager}<div class="clearfix"></div>',
    'itemsCssClass' => 'table table-hover',
    'pagerCssClass' => 'pagination',
    'blankDisplay' => 'Buy',
    'pager' => array(//通过pager设置样式   默认为CLinkPager
        'cssFile' => '',
        'prevPageLabel' => '<<',
        'nextPageLabel' => '>>',
        'header' => '',
        'maxButtonCount' => 8,
        'htmlOptions' => array('class' => 'pull-right'),
    ),
    'columns' => array(
        array(
            'header' => 'Product',
            'name' => 'p_name',
        ),
        array(
            'header' => 'Price('.$currency["tag"].')',
            'name' => 'p_price',
            'value' => '$data->getCurrencyTag() . $data->itemPrice()',
            'htmlOptions' => array('class' => 'price'),
        ),
        array(
            'type' => 'raw',
            'header' => 'QUANTITY',
            'value' => '$data->itemNumDropDownList()',
        ),
        array(
            'type' => 'raw',
            'value' => '$data->createBuyButton()',
            'htmlOptions' => array('width' => '100'),
        )
    ),
));
?>
<hr/>
<?php echo $model->info; ?>
<script>
    var price_tag = "<?php echo $currency['tag'];?>";
    function computePrice(obj){
        var un_price = $(obj).next('input').val();
        var nums = $(obj).val().split(':');
        var discount = nums[1]>1?nums[1]/100:nums[1];
        $(obj).parent('td').next('td').find('form').find('input[name=num]').val(nums[0]);
        $(obj).parent('td').prev().html( price_tag + Math.round( un_price * nums[0] * discount * 100) / 100 );
    }
</script>
